var express = require('express');
var router = express.Router();
var path = require('path');
var fs = require("fs");
const userServices = require('../services/studentServices');

/* GET users listing. */
router.get('/', function (req, res, next) {
    res.send('respond with a resource');
});

/* 获取学生列表 */
router.get('/studentList', function (req, res, next) {
    userServices.studentList((data) => {
        res.end(JSON.stringify(data));
    });
});

/* 添加学生 */
router.post('/addStudent', function (req, res, next) {
    userServices.addStudent(req.body, (data) => {
        res.end(JSON.stringify(data));
    })
})

/* 删除学生 */
router.delete('/deleteStudent', function (req, res, next) {
    userServices.deleteStudent(req.body, (data) => {
        res.end(JSON.stringify(data));
    })
})

/* 修改学生 */
router.put('/putStudent', function (req, res, next) {
    userServices.putStudent(req.body, (data) => {
        res.end(JSON.stringify(data));
    })
})

/* ID获取学生 */
router.get('/:studentId', function (req, res) {
    userServices.getStudentById(req.params, data => {
        res.end(JSON.stringify(data));
    })
})

module.exports = router;